package com.yogee.topseller.activity.my;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lljjcoder.citypickerview.widget.CityPicker;
import com.yogee.core.base.HttpActivity;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.loading.CustomProgressDialog;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.NetUtil;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.login.model.bean.SMSbean;
import com.yogee.topseller.bean.CardReturnBean;
import com.yogee.topseller.bean.GetBankInfoBean;
import com.yogee.topseller.bean.OrderInfoBean;
import com.yogee.topseller.bean.ResultBean;
import com.yogee.topseller.bean.SetBankInfoBean;
import com.yogee.topseller.http.Config;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.EditCheckUtil;
import com.yogee.topseller.utils.FileStorage;
import com.yogee.topseller.utils.LogUtils;
import com.yogee.topseller.utils.NeedPermissions;
import com.yogee.topseller.view.ClearEditText;
import com.yogee.topseller.view.VoucherPop;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class AddCardActivity extends HttpActivity implements VoucherPop.OnIdCardPopClickListener{
    @BindView(R.id.add_card_sure)
    TextView addCardSure;
    @BindView(R.id.add_card_default)
    ImageView addCardDefault;
    boolean isClick = true;
    int mRadomNumber = 0;
    @BindView(R.id.add_card_get)
    TextView addCardGet;
    @BindView(R.id.add_card_phone)
    ClearEditText addCardPhone;
    @BindView(R.id.add_card_num)
    ClearEditText addCardNum;
    @BindView(R.id.add_card_name)
    ClearEditText addCardName;
    @BindView(R.id.add_card_location)
    TextView addCardLocation;
    @BindView(R.id.add_card_bank)
    ClearEditText addCardBank;
    @BindView(R.id.add_card_code)
    EditText addCardCode;
    @BindView(R.id.layout_location)
    RelativeLayout locationLayout;
    boolean isGetCode = false;
    @BindView(R.id.add_card_titlelayout)
    TitleLayout titlelayout;
    @BindView(R.id.add_card_data_bg)
    View addCardDataBg;

    private CountDownTimer timer;
    private String isDefault = "0";
    private String cityArea;

    private int GALLERY_RESULT = 150;
    private int CAMERA_RESULT = 100;

    private File photoFile;
    private CustomProgressDialog progressBar;

    private String carId="";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_card;
    }

    @Override
    protected void initView() {
        titlelayout.setActivity(this);
        carId = getIntent().getStringExtra("carId");
        if(!TextUtils.isEmpty(carId)){
            titlelayout.setTitle("编辑银行卡");
            getCardInfo(carId);
        }else{
            titlelayout.setTitle("新增银行卡");
        }

        mRadomNumber = AppUtil.getRandomNumber(4);
        LogUtils.e("soso","验证码:"+mRadomNumber);

    }

    private void getCardInfo(String cardId){
        HttpManager.getInstance().getBankInfoKa(cardId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GetBankInfoBean.BankListBean>() {
            @Override
            public void onNext(GetBankInfoBean.BankListBean o) {
                setViewData(o);
            }
        }, this));
    }

    private void setViewData(GetBankInfoBean.BankListBean bean){
        addCardNum.setText(bean.getBankNumber());
        addCardName.setText(bean.getName());
        addCardLocation.setText(bean.getBankAddress());
        addCardBank.setText(bean.getBank());
        addCardPhone.setText(bean.getPhone());
        if(bean.getIfDefault().equals("1"))
            addCardDefault.setImageResource(R.drawable.select1);
        else
            addCardDefault.setImageResource(R.drawable.unselect1);
    }

    @OnClick({R.id.layout_location, R.id.add_card_sure, R.id.add_card_default, R.id.add_card_get, R.id.tv_upload})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_location:
                if (TextUtils.isEmpty(cityArea)) {
                    cityArea = "北京市 北京市";
                }
                CityPicker cityPicker = new CityPicker.Builder(AddCardActivity.this)
                        .textSize(20)
                        .title("城市")
                        .backgroundPop(0x20000000)
                        .titleBackgroundColor("#fefefe")
                        .titleTextColor("#1f1f1f")
                        .confirTextColor("#1f1f1f")
                        .cancelTextColor("#1f1f1f")
                        .province(cityArea.split(" ")[0])
                        .city(cityArea.split(" ")[1])
                        .textColor(Color.parseColor("#6c6c6c"))
                        .provinceCyclic(true)
                        .cityCyclic(false)
                        .districtCyclic(false)
                        .visibleItemsCount(7)
                        .itemPadding(10)
                        .onlyShowProvinceAndCity(true)
                        .build();
                cityPicker.show();

                cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() {
                    @Override
                    public void onSelected(String... citySelected) {
                        String provinceSelect = citySelected[0];
                        String citySelect = citySelected[1];

                        cityArea = provinceSelect + " " + citySelect;
                        addCardLocation.setText(cityArea);
                    }
                });
                break;
            case R.id.add_card_sure:
                if (TextUtils.isEmpty(addCardNum.getText().toString())) {
                    ToastUtils.showToast(this, "请输入银行卡号");
                } else if (!EditCheckUtil.checkBankCard(addCardNum.getText().toString())) {
                    ToastUtils.showToast(this, "请输入正确银行卡号");
                } else if (TextUtils.isEmpty(addCardName.getText().toString())) {
                    ToastUtils.showToast(this, "请输入收件人姓名");
                } else if (addCardLocation.getText().toString().equals("选择所在地区")) {
                    ToastUtils.showToast(this, "请选择开户行所在地");
                } else if (TextUtils.isEmpty(addCardBank.getText().toString())) {
                    ToastUtils.showToast(this, "请输入开户行名称");
                } else if (TextUtils.isEmpty(addCardPhone.getText().toString())) {
                    ToastUtils.showToast(this, "请输入手机号");
                } else if (!AppUtil.validatePhone(addCardPhone.getText().toString())) {
                    ToastUtils.showToast(this, "请输入正确的手机号");
                } else if (!isGetCode) {
                    ToastUtils.showToast(this, "请先获取验证码");
                } else if (TextUtils.isEmpty(addCardCode.getText().toString())) {
                    ToastUtils.showToast(this, "请输入验证码");
                } else if (!addCardCode.getText().toString().equals(String.valueOf(mRadomNumber))) {
                    ToastUtils.showToast(this, "请输入正确的验证码");
                } else {
                    if(TextUtils.isEmpty(carId))
                        setBankInfo(AppUtil.getUserId(this), addCardNum.getText().toString(), addCardLocation.getText().toString(),
                            addCardName.getText().toString(), addCardBank.getText().toString(), addCardPhone.getText().toString(), isDefault);
                    else{
                        editCardInfo(AppUtil.getUserId(this), addCardNum.getText().toString(), addCardLocation.getText().toString(),
                                addCardName.getText().toString(), addCardBank.getText().toString(), addCardPhone.getText().toString(), isDefault);
                    }
                }

                break;
            case R.id.add_card_default:
                if (isClick) {
                    addCardDefault.setImageResource(R.drawable.select1);
                    isDefault = "1";
                } else {
                    addCardDefault.setImageResource(R.drawable.unselect1);
                    isDefault = "0";
                }
                isClick = !isClick;
                break;
            case R.id.add_card_get:
                isGetCode = true;
                if (AppUtil.isFastDoubleClick(500)) {
                    return;
                }
                if ("重新发送".equals(addCardGet.getText().toString())) {
                    mRadomNumber = AppUtil.getRandomNumber(4);
                }
                if (validate()) {
//                    addCardGet.setTextColor(getResources().getColor(R.color.gray));
//                    addCardGet.setBackgroundDrawable(getResources().getDrawable(R.drawable.corners5_stroke1gray));
                    addCardGet.setClickable(false);
                    sendSMS(AddCardActivity.this, addCardPhone.getText().toString(), mRadomNumber);
                }
                break;
            case R.id.tv_upload:
//                replacePhoroOrCorver();
                if (TextUtils.isEmpty(addCardNum.getText().toString())) {
                    ToastUtils.showToast(this, "请输入银行卡号");
                } else if (!EditCheckUtil.checkBankCard(addCardNum.getText().toString())) {
                    ToastUtils.showToast(this, "请输入正确银行卡号");
                } else if (TextUtils.isEmpty(addCardName.getText().toString())) {
                    ToastUtils.showToast(this, "请输入收件人姓名");
                } else if (addCardLocation.getText().toString().equals("选择所在地区")) {
                    ToastUtils.showToast(this, "请选择开户行所在地");
                } else if (TextUtils.isEmpty(addCardBank.getText().toString())) {
                    ToastUtils.showToast(this, "请输入开户行名称");
                } else if (TextUtils.isEmpty(addCardPhone.getText().toString())) {
                    ToastUtils.showToast(this, "请输入手机号");
                } else if (!AppUtil.validatePhone(addCardPhone.getText().toString())) {
                    ToastUtils.showToast(this, "请输入正确的手机号");
                } else if (!isGetCode) {
                    ToastUtils.showToast(this, "请先获取验证码");
                } else if (TextUtils.isEmpty(addCardCode.getText().toString())) {
                    ToastUtils.showToast(this, "请输入验证码");
                } else if (!addCardCode.getText().toString().equals(String.valueOf(mRadomNumber))) {
                    ToastUtils.showToast(this, "请输入正确的验证码");
                } else {
                    if(TextUtils.isEmpty(carId))
                        setBankInfo(AppUtil.getUserId(this), addCardNum.getText().toString(), addCardLocation.getText().toString(),
                                addCardName.getText().toString(), addCardBank.getText().toString(), addCardPhone.getText().toString(), isDefault);
                        // 修改
                    else{
                        editCardInfo(AppUtil.getUserId(this), addCardNum.getText().toString(), addCardLocation.getText().toString(),
                                addCardName.getText().toString(), addCardBank.getText().toString(), addCardPhone.getText().toString(), isDefault);
                    }
                }
                break;
        }
    }

    public void replacePhoroOrCorver() {
        List<String> permissions = new NeedPermissions(this).cameraPermissions();
        if (permissions.size() > 0) {
            String[] permission = new String[permissions.size()];
            for (int i = 0; i < permissions.size(); i++) {
                permission[i] = permissions.get(i);
            }
            ActivityCompat.requestPermissions(this, permission, 1);
        } else {
            new VoucherPop(addCardDataBg, this, this).idCardPop();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == 1) {
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(this, "部分所需权限未开启，将影响功能正常使用，请开启权限！", Toast.LENGTH_LONG).show();
                }
            }
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void onCameraClick() {
        toCamera();
    }

    public void toCamera() {
        Intent intent = new Intent();
        Uri uri;
        File file = new FileStorage().createIconFile();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(this, "com.yogee.topseller.fileprovider", file);//通过FileProvider创建一个content类型的Uri
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将拍取的照片保存到指定URI
        photoFile = file;
        startActivityForResult(intent, CAMERA_RESULT);
    }

    @Override
    public void onAlbumClick() {
        Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(i, GALLERY_RESULT);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CAMERA_RESULT && resultCode == RESULT_OK) {
            updatePhoto(Config.APPCODE, photoFile);
        }
        if (requestCode == GALLERY_RESULT && resultCode == RESULT_OK) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            updatePhoto(Config.APPCODE, new File(picturePath));
        }
    }

    private void updatePhoto(String appCode, File file) {
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.showToast(AddCardActivity.this, "网络中断了，请重新链接网络。");
            return;
        }
        //显示加载框
        if (progressBar == null){
            progressBar = CustomProgressDialog.createDialog(AddCardActivity.this);
        }else{
            progressBar.show();
        }
        //组装调取银行卡验证api的数据
        JSONObject object = null;
        JSONArray inputs = new JSONArray();
        JSONObject image = new JSONObject();
        try {
            JSONObject temp = new JSONObject();
            image.put("dataType", 50);
            image.put("dataValue", Bitmap2StrByBase64(BitmapFactory.decodeFile(file.getPath())));
            temp.put("image", image);
            inputs.put(temp);
            object = new JSONObject();
            object.put("inputs", inputs);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        OkHttpClient okHttpClient = new OkHttpClient();
        Request.Builder builder = new Request.Builder();
        RequestBody requestBody = RequestBody
                .create(MediaType.parse("text/plain;chaset=utf-8"), object.toString());
        Request request = builder.post(requestBody)
                .url("http://yhk.market.alicloudapi.com/rest/160601/ocr/ocr_bank_card.json")
                .addHeader("Authorization", "APPCODE " + appCode)
                .addHeader("Content-Type", "application/json; charset=UTF-8")
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //失败处理
                        if (progressBar.isShowing()){
                            progressBar.dismiss();
                        }
                        ToastUtils.showToast(AddCardActivity.this, "校验失败，请手动输入银行卡号");
                    }
                });
            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //成功处理
                        if (progressBar.isShowing()){
                            progressBar.dismiss();
                        }
                        //组装json来回显银行卡号
                        try {
                            Gson gson = new Gson();
                            CardReturnBean bean = gson.fromJson(response.body().string().replace("\n",""),CardReturnBean.class);
                            String jsonStr = bean.getOutputs().get(0).getOutputValue().getDataValue().toString().replace("\\","");
                            CardReturnBean.DataValue dataValue = gson.fromJson(jsonStr,CardReturnBean.DataValue.class);
                            if (dataValue.getCard_num() != null && !dataValue.getCard_num().equals("")){
                                addCardNum.setText(dataValue.getCard_num());
                            }else{
                                ToastUtils.showToast(AddCardActivity.this, "校验失败，请手动输入银行卡号");
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
    }

    public String Bitmap2StrByBase64(Bitmap bit) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);//参数100表示不压缩
        byte[] bytes = bos.toByteArray();
        return Base64.encodeToString(bytes, Base64.DEFAULT);
    }


    public Boolean validate() {
        if (TextUtils.isEmpty(addCardPhone.getText())) {
            ToastUtils.showToast(this, "请输入手机号");
            return false;
        } else if (!AppUtil.validatePhone(addCardPhone.getText().toString())) {
            ToastUtils.showToast(this, "请输入正确的手机号");
            return false;
        }
        return true;
    }

    public void sendSMS(final Activity activity, final String phoneNum, final int random) {
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.showToast(activity, "网络中断了，请重新链接网络。");
            return;
        }
        if (!TextUtils.isEmpty(phoneNum)) {
            new Thread() {
                public void run() {
                    try {
                        //准备获取短信验证码需要的基本信息
                        String result = null;
                        String url = "http://v.juhe.cn/sms/send";//请求接口地址
                        Map params = new HashMap();//请求参数
                        params.put("mobile", phoneNum);//接收短信的手机号码
                        params.put("tpl_id", Config.TPL_ID);//短信模板ID，请参考个人中心短信模板设置
                        params.put("tpl_value", Config.TPL_VALUE + random);//变量名和变量值对。如果你的变量名或者变量值中带有#&=中的任意一个特殊符号，请先分别进行urlencode编码后再传递，<a href="http://www.juhe.cn/news/index/id/50" target="_blank">详细说明></a>
                        params.put("key", Config.APPKEY);//应用APPKEY(应用详细页查询)
                        params.put("dtype", "");//返回数据的格式,xml或json，默认json
                        try {
                            result = net(url, params, "GET");
                            Gson gson = new Gson();
                            final SMSbean returnBean = gson.fromJson(result, SMSbean.class);
                            //短信发送完成，更新UI操作
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    updateCheckCode(returnBean);
//                                    mView.updateCheckCode(returnBean);
                                }
                            });
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }

    public static String net(String strUrl, Map params, String method) throws Exception {
        HttpURLConnection conn = null;
        BufferedReader reader = null;
        String rs = null;
        try {
            StringBuffer sb = new StringBuffer();
            if (method == null || method.equals("GET")) {
                strUrl = strUrl + "?" + urlencode(params);
            }
            URL url = new URL(strUrl);
            conn = (HttpURLConnection) url.openConnection();
            if (method == null || method.equals("GET")) {
                conn.setRequestMethod("GET");
            } else {
                conn.setRequestMethod("POST");
                conn.setDoOutput(true);
            }
            conn.setRequestProperty("User-agent", Config.USERAGENT);
            conn.setUseCaches(false);
            conn.setConnectTimeout(Config.DEF_CONN_TIMEOUT);
            conn.setReadTimeout(Config.DEF_READ_TIMEOUT);
            conn.setInstanceFollowRedirects(false);
            conn.connect();
            if (params != null && method.equals("POST")) {
                try {
                    DataOutputStream out = new DataOutputStream(conn.getOutputStream());
                    out.writeBytes(urlencode(params));
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
            InputStream is = conn.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, Config.DEF_CHATSET));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sb.append(strRead);
            }
            rs = sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (conn != null) {
                conn.disconnect();
            }
        }
        return rs;
    }

    public static String urlencode(Map<String, Object> data) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry i : data.entrySet()) {
            try {
                sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

    public void updateCheckCode(SMSbean smSbean) {
        if (Integer.parseInt(smSbean.getError_code()) == 0) {
            countDownTimer();
            ToastUtils.showToast(this, "验证码已经发送");
        } else {
            addCardGet.setClickable(true);
            ToastUtils.showToast(this, smSbean.getError_code() + ":" + smSbean.getReason());
        }
    }

    private void countDownTimer() {
        timer = new CountDownTimer(60000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                addCardGet.setText("重新发送" + "(" + millisUntilFinished / 1000 + "s)");
//                addCardGet.setTextColor(getResources().getColor(R.color.white));
//                addCardGet.setBackgroundDrawable(getResources().getDrawable(R.drawable.corens_100_gary));
                addCardGet.setClickable(false);
            }

            @Override
            public void onFinish() {
                addCardGet.setText("重新发送");
//                addCardGet.setTextColor(getResources().getColor(R.color.theme_color));
//                addCardGet.setBackgroundDrawable(getResources().getDrawable(R.drawable.corens_100_styles));
                addCardGet.setClickable(true);
            }
        };
        timer.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null)
            timer.cancel();
    }

    private void setBankInfo(String userId, String cardNumber, String bankAddress,
                             String name, String bank, String userPhone, String isDefaults) {
        HttpManager.getInstance().setBankInfo(userId, cardNumber, bankAddress, name, bank, userPhone, isDefaults)
                .compose(bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<SetBankInfoBean>() {
            @Override
            public void onNext(SetBankInfoBean o) {
                AddCardActivity.this.loadingFinished();
                if (o.getResult().equals("1")) {
                    Toast.makeText(AddCardActivity.this, "添加银行卡成功", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }, this));
    }

    private void editCardInfo(String userId, String cardNumber, String bankAddress,
                             String name, String bank, String userPhone, String isDefaults) {
        if(pd==null)
            pd = CustomProgressDialog.createDialog(this);
        pd.show();
        HttpManager.getInstance().updateBankInfoka(userId,carId, cardNumber, bankAddress, name, bank, userPhone, isDefaults)
                .compose(bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<ResultBean>() {
            @Override
            public void onNext(ResultBean o) {
                pd.dismiss();
                if (o.getResult().equals("1")) {
                    Toast.makeText(AddCardActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }, this));
    }

    @Override
    public void showMsg(String msg) {
        super.showMsg(msg);
        if(pd!=null&&pd.isShowing())
            pd.dismiss();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

}
